// 封装一个响应式的函数
class Depend {
  constructor() {
    this.reactiveFns = []
  }
  appDepend(reactiveFn) {
    this.reactiveFns.push(reactiveFn)
  }
  notify() {
    this.reactiveFns.forEach(fn => {
      fn()
    })
  }
}

const depend = new Depend()

function watchFn(fn) {
  depend.appDepend(fn)
}



// 对象的响应式
const obj = {
  name: 'why', // new Depend 对应一个depend对象
  age: 18 // new Depend 对应一个depend对象
}

watchFn(function () {
  const newName = obj.name
  console.log('你好啊,李银河');
  console.log('Hello World');
  console.log(obj.name);
})


watchFn(function () {
  console.log('demo响应');
})


obj.name = 'kobe'
depend.notify()